package com.hxt.xt.dao.crud;

import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;

import javax.annotation.Resource;

import com.hxt.framework.mybatis.Page;
import com.hxt.framework.mybatis.crud.IDao;
import com.hxt.framework.mybatis.crud.IDaoControl;

public class HxtDaoControlImpl<M, PK extends Serializable> implements IDaoControl<M, PK> {

	private String className = null;

	@Resource(name = "idao_xt")
	private IDao<M, PK> iDao;


	@SuppressWarnings("unchecked")
	public HxtDaoControlImpl() {
		Class<?> c = getClass();
		Type type = c.getGenericSuperclass();
		if (type instanceof ParameterizedType) {
			Type[] parameterizedType = ((ParameterizedType) type).getActualTypeArguments();
			Class<M> entityClass = (Class<M>) parameterizedType[0];
			className = entityClass.getSimpleName();
		}
	}

	@Override
	public M getObjectById(PK id) {
		return this.iDao.getObjectById(id, className);
	}

	@Override
	public List<M> getListByModel(Object m) {
		return this.iDao.getListByModel(m, className);
	}

	@Override
	public Page<M> getPageListByModel(Object m, int pagesize, int pageno) {
		return this.iDao.getPageListByModel(m, pagesize, pageno, className);
	}

	@Override
	public M getObjectByModel(Object m) {
		return this.iDao.getObjectByModel(m, className);
	}

	@Override
	public Integer saveObject(Object m) {
		return this.iDao.saveObject(m, className);
	}

	@Override
	public Integer updateObjectById(Object m) {
		return this.iDao.updateObjectById(m, className);
	}

	@Override
	public Integer deleteObjectById(PK id) {
		return this.iDao.deleteObjectById(id, className);
	}

}
